//
//  HJMainViewController.swift
//  zhangmiSinweibo
//
//  Created by zhangmi on 16/5/19.
//  Copyright © 2016年 Paramount Pictures. All rights reserved.
//

//cmd + shfit + J
//获取文件焦点

import UIKit

class HJMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        //添加TabController的子视图控制器
        addChildViewControllers()
    
    
    
    }
    
    //private 表示是私有的意思, 是相对于当前的文件是私有的
    private func addChildViewControllers(){
      
       addChildViewController(HJHomeController(), title: "首页", imageName: "tabbar_home")
       addChildViewController(HJMessageController(), title: "消息", imageName: "tabbar_message_center")
       addChildViewController(HJDiscoverController(), title: "发现", imageName: "tabbar_discover")
       addChildViewController(HJProfileController(), title: "我的", imageName: "tabbar_profile")
    }
    
    
    private func addChildViewController(vc: UIViewController, title: String, imageName: String) {
        
        //设置标签, Xcode的bug, 只设置文字, 可能不会显示, 需要同时设置图片的背景
//        vc.tabBarItem.title = title
//        //设置vc的导航控制器的导航条的模型对象的title
//        vc.navigationItem.title = "hehehe"
        
        //如果标签和导航条的title是一样的
        vc.title = title
        vc.tabBarItem.image = UIImage(named: imageName)
        
        //设置选中时图片. 需要设置渲染的模式. 选中的图片颜色会变化, UI合作命名规则
        vc.tabBarItem.selectedImage = UIImage(named:imageName + "_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        //设置title的颜色
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName :UIColor.orangeColor()], forState: .Selected)
 
        
//        //统一设置所有的title的颜色
//        tabBar.tintColor = UIColor.orangeColor()
        
        vc.tabBarItem.titlePositionAdjustment = UIOffset(horizontal: 0, vertical: -3)
        //内嵌到导航视图控制器中
        let nav = UINavigationController(rootViewController: vc)
        //添加子视图控制器
        addChildViewController(nav)
        
    }
   
    
    
//private 是相对当前文件的
class person: NSObject{
        func haha() {
            let tab = HJMainViewController()
            
            tab.addChildViewControllers()
        }
    }
    
    
}
